package com.example.weatherview.controller;

import com.example.citycommon.dto.WeatherResponse;
import com.example.citycommon.pojo.City;
import com.example.weatherview.client.CityClient;
import com.example.weatherview.client.WeatherClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class WeatherController {

    @Autowired
    WeatherClient weatherClient;

     @Autowired
     CityClient cityClient;

//    http://localhost:9500/weather/search?cityid=101010100
    @GetMapping("/search")
    public ModelAndView showWeather(@RequestParam String cityid) {
        ModelAndView mav = new ModelAndView("weather"); // 确保这里返回的视图名称是 "weather"
        WeatherResponse response = weatherClient.search(cityid);
        List<City> list = cityClient.list();
        mav.addObject("response", response);
        mav.addObject("citys",list);
        mav.addObject("cityid",cityid);
        System.out.println(list);
        System.out.println(cityid);
        return mav;
    }
}
